package com.typhoon.spring_shiro.controller.kaptcha;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * 图形验证码控制器
 * 
 * @author Typhoon
 * @date 2017-05-23 19:39
 * @since V2.0
 */

@Controller
@RequestMapping("kaptcha")
public class CustomCaptchaController extends AbstractCaptchaController {

	/**
	 * 获取图形验证码
	 * 
	 * @param request
	 * @param response
	 * @throws Exception
	 */
	@RequestMapping(value = "/get-captcha-image.do")
	public void getCaptchaImg(HttpServletRequest request, HttpServletResponse response) throws Exception {
		super.getCaptcha(request, response); // 获取验证码
	}

	/**
	 * 校验图形验证码
	 * 
	 * @param params
	 * @param request
	 * @param response
	 */
	@RequestMapping(value = "/captcha-validate.do")
	public void captchaValidate(@RequestBody Map<String, String> params, HttpServletRequest request, HttpServletResponse response) {
		String userCode = params.get("userCode");
		if(!super.validateUserCode(userCode, request, response)) {
			return;
		}
		this.putSuccessResult(response);
	}
}
